#include<reg51.h>

#define NODE1_ADDR 1
#define NODE2_ADDR 2

unsigned char pointer_1 = 0, pointer_2 = 0;

unsigned char str[] = {"0123456789ABCDEF"};

void proc_key(unsigned char node_number);

void delay(unsigned int time)
{
    unsigned char i, j;
    for (i = 0; i < 130; i++)
    {
        for(j = 0;j < time; j++);
    }
}

void main()
{
    SCON = 0xe0;
    TMOD = 0x20;
    TH1 = TL1 = 0xfd;
    TR1 = 1;
    while(1)
    {
        P1 = 0xff;
        while(P1 == 0xff);
        if (P1 == 0xfe)
        {
           proc_key(NODE1_ADDR); 
        }else if (P1 == 0xfd)
        {
            proc_key(NODE2_ADDR);
        }
    }
}

void proc_key(unsigned char node_number)
{
    delay(200);
    TB8 = 1;//??
    SBUF = node_number;
    while(!TI);
    TI = 0;
    TB8 = 0;//??
    switch (node_number)
    {
        case 1:
            SBUF = str[pointer_1++];
            if (pointer_1>=16)
            {
                pointer_1 = 0;
            }
                
            break;
        
        case 2:
            SBUF = str[pointer_2++];
            if (pointer_2>=16)
            {
                pointer_2 = 0;
            }
            break;
        default:
            break;
        }
    while(!TI);
    TI = 0;
}